import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:huajianshe_app/utils/SpUtil.dart';
import 'package:oktoast/oktoast.dart';
import 'package:im_flutter_sdk/im_flutter_sdk.dart';

import 'base/NetworkManager.dart';
import 'common/AppRouter.dart';
import 'common/C.dart';
import 'network/interceptor.dart';
import 'package:flutter_screenutil/screenutil_init.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SpUtil.getInstance();
  await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  NetworkManager().setConfig(new NetworkConfig(
      // baseUrl: 'http://www.cairuoyu.com/api/p4/', //正式地址
      baseUrl: 'http://hjs.91tests.net/api/',  //测试地址
      interceptors: [HeaderInterceptor(), LoggingInterceptor()]));
  //环信
  // EMOptions options = EMOptions(appKey: 'easemob-demo#easeim');
  EMOptions options = EMOptions(appKey: '1123210819175971#demo');
  EMPushConfig config = EMPushConfig();
  options.debugModel = true;
  options.pushConfig = config;
  EMClient.getInstance.init(options).then((value) => null);
  runApp(MyApp());
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarBrightness: Brightness.dark));

}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return
      ScreenUtilInit(
        designSize: Size(375, 667),
        builder: () {
          return OKToast(
            child: MaterialApp(
              // theme: themeModel.themeData(),
              theme: ThemeData(
                  brightness: Brightness.light,
                  primaryColorBrightness: Brightness.dark,
                  accentColorBrightness: Brightness.dark,
                  accentColor: C.primary,
                  textTheme: TextTheme(
                      bodyText1: TextStyle(fontSize: 14, color: C.gray333)
                  ).apply(
                    bodyColor: C.primary,
                    displayColor: C.primary,
                  )
              ),
              onGenerateRoute: AppRouter.generateRoute,
              initialRoute: RouteName.SPLASH, // RouteName.ROUTER_MEETING,  //RouteName.SPLASH  //
            ),
          );
        }
    );
  }
}
